package hauwei.year2024.month3;
import java.util.*;

public class circleDepend {
    static Map<Integer, ArrayList<Integer>> map = new HashMap<>();
    static TreeSet<Integer>resTreeSet;
    static boolean isFind=false;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mapLen = sc.nextInt();
        for (int i = 0; i < mapLen; i++) {
            int setLen = sc.nextInt()-1;
            int num = sc.nextInt();
            ArrayList<Integer> set = new ArrayList<>();
            for (int j = 0; j < setLen; j++) {
                set.add(sc.nextInt());
            }
            map.put(num, set);
        }
        sc.close();
        Set<Integer> keys = map.keySet();

        for (Integer integer : keys) {
            TreeSet<Integer> objects = new TreeSet<>();
            objects.add(integer);
            dfs(map.get(integer),integer,objects);
        }
        //resTreeSet.forEach(System.out::print);
    }

    public static void dfs(ArrayList<Integer>list,int start,TreeSet<Integer>treeSet) {
        if(list==null || list.isEmpty()||isFind){
            return;
        }
        list.forEach(x->{
            if(x==start){
                resTreeSet=treeSet;
                if(!isFind){
                    resTreeSet.forEach(System.out::print);
                    System.out.print(start);
                    isFind=true;
                }
                return;
            }
            treeSet.add(x);
            dfs(map.get(x),start,treeSet);
        });
    }
}
